package com.example.selfservicestation.util

import android.widget.Toast
import com.example.selfservicestation.MyApplication

fun showToast(showString: String? = null, resId: Int? = null, duration: Int = Toast.LENGTH_SHORT) {
    val context = MyApplication.instance.applicationContext
    showString?.let {
        Toast.makeText(context, it, duration).show()
    }
    resId?.let {
        Toast.makeText(context, context.getString(it), duration).show()
    }
}

//index 从0开始
fun getBitValueFrom8Bits(byte: Byte, index: Int): Int{
    val intValue = byte.toInt()
    val leftMove = 32 - 1 -index
    val rightMove = 32 - 1
    return (intValue shl leftMove) ushr rightMove
}